package com.itruth.data.dao;

import com.itruth.base.ItruthApp;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper{

	private static final String DB_NAME = "itruth";
	private static final int DB_VERSION = 1;
	
	private static DbHelper instance;
	
	private DbHelper (Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}
	
	public static DbHelper getIns() {
		
		if (null == instance) {
			synchronized (DbHelper.class) {
				if (null == instance) {
					instance = new DbHelper(ItruthApp.getIns());
				}
			}
		}
		return instance;
	}
	
	
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		//感悟表，存放用户输入的任何文字，图片，语音信息
		db.execSQL("create table if not exists apperception(id integer primary key autoincrement, content varchar2, time timestamp)");
		db.execSQL("create table if not exists draft(id integer primary key autoincrement, content varchar2)");
		db.execSQL("create table if not exists share(id integer primary key autoincrement, content varchar2, author varchar2, server_id int, share_time varchar2)");
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("drop table if exists apperception");
		db.execSQL("drop table if exists draft");
		db.execSQL("drop table if exists share");
		onCreate(db);
	}
	
}
